home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / Plug-in - WireFrame Renderer / SR_Line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  4.0 KB  |  170 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        SR_Line.c                                                 **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:     Polyline routines                                          **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1996-1997 Apple Computer, Inc.  All rights reserved.     **
  11.  **                                                                          **
  12.  **                                                                          **
  13.  *****************************************************************************/
  14. #include <assert.h>
  15.  
  16. #include "QD3D.h"
  17. #include "SR.h"
  18.  
  19.  
  20. /*===========================================================================*\
  21.  *
  22.  *    Routine:    SR_Geometry_Line()
  23.  *
  24.  *    Comments:    
  25.  *
  26. \*===========================================================================*/
  27.  
  28. TQ3Status SR_Geometry_Line(
  29.     TQ3ViewObject             view, 
  30.     TSRPrivate                *srPrivate,
  31.     TQ3GeometryObject         line,
  32.     TQ3LineData                *lineData)
  33. {
  34.     unsigned long            numVertices;
  35.     TQ3Boolean                highlightState;
  36.     TQ3XClipMaskState        clipMaskState;
  37.     TQ3ColorRGB                color;
  38.     
  39.     UNUSED(line);
  40.  
  41.     assert(view         != NULL);
  42.     assert(srPrivate    != NULL);
  43.     assert(lineData        != NULL);
  44.     
  45.     /*
  46.      *  Call the application's idle progress method, via the view.  If
  47.      *  the app's method returns kQ3Failure, then we don't go on.
  48.      */
  49.     if (SR_IdleProgress(view, srPrivate) == kQ3Failure) {
  50.         return (kQ3Success);
  51.     }
  52.     
  53.     /*
  54.      *  Sanity check. If no draw region, bail.
  55.      */
  56.     if (srPrivate->drawRegion == NULL) {
  57.         return (kQ3Success);
  58.     }
  59.     
  60.     /*
  61.      *  Find out if we're clipped out or not. No reason to go any
  62.      *  further if the region is obscured or entirely off-screen. 
  63.      */
  64.     Q3XDrawRegion_GetClipFlags(srPrivate->drawRegion, &clipMaskState);
  65.     if (clipMaskState == kQ3XClipMaskNotExposed) {
  66.         return (kQ3Success);
  67.     }
  68.  
  69.     /*
  70.      *  Lazy-evaluate the various transforms for the pipeline
  71.      */
  72.     if (SR_UpdatePipeline(srPrivate) == kQ3Failure) {
  73.         return (kQ3Failure);
  74.     }
  75.  
  76.     /*
  77.      *  Lines have two vertices :-)
  78.      */
  79.     numVertices = 2;
  80.             
  81.     /*
  82.      *  Highlight state and  color are from the view, unless
  83.      *  overridden by the lineAttributeSet
  84.      */
  85.     highlightState     = srPrivate->viewHighlightState;
  86.     color             = srPrivate->viewDiffuseColor;
  87.     
  88.     /*
  89.      *  Check if we have a line attribute set.
  90.      *  If so, then see if we can get a color and highlight state
  91.      *  out of it. 
  92.      */
  93.     if (lineData->lineAttributeSet != NULL) {
  94.         TQ3XAttributeMask    attributeMask;
  95.         
  96.         attributeMask = Q3XAttributeSet_GetMask(lineData->lineAttributeSet);
  97.         
  98.         if (attributeMask & kQ3XAttributeMaskDiffuseColor) {
  99.             Q3AttributeSet_Get(
  100.                 lineData->lineAttributeSet,
  101.                 kQ3AttributeTypeDiffuseColor,
  102.                 &color);
  103.         }
  104.  
  105.         if (attributeMask & kQ3XAttributeMaskHighlightState) {
  106.             Q3AttributeSet_Get(
  107.                 lineData->lineAttributeSet, 
  108.                 kQ3AttributeTypeHighlightState, 
  109.                 &highlightState);
  110.         }
  111.     }
  112.  
  113.     /*
  114.      *  If we're highlighting, then see if we can get a highlight color
  115.      *  out of the view's attribute set. Use that as the color, if it's there.
  116.      */
  117.     if ((highlightState == kQ3True) &&
  118.         (srPrivate->viewHighlightAttributeSet != NULL)) {
  119.         TQ3XAttributeMask    attributeMask;
  120.         
  121.         attributeMask = Q3XAttributeSet_GetMask(srPrivate->viewHighlightAttributeSet);
  122.         
  123.         if (attributeMask & kQ3XAttributeMaskDiffuseColor) {
  124.             Q3AttributeSet_Get( 
  125.                 srPrivate->viewHighlightAttributeSet, 
  126.                 kQ3AttributeTypeDiffuseColor, 
  127.                 &color);
  128.         }
  129.     }
  130.     
  131.     /*
  132.      *  Dispatch to the proper pipeline, depending on the fill style.
  133.      */
  134.     switch (srPrivate->viewFillStyle) {
  135.         case kQ3FillStyleFilled:    
  136.         case kQ3FillStyleEdges: {
  137.             if (SR_LinePipe(
  138.                     srPrivate, 
  139.                     (TQ3Point3D *)lineData->vertices, 
  140.                     numVertices, 
  141.                     sizeof(TQ3Vertex3D),
  142.                     &color,
  143.                     NULL,
  144.                     DO_POLYLINE) == kQ3Failure) {
  145.                 return (kQ3Failure);
  146.             }
  147.             break;
  148.         }
  149.         case kQ3FillStylePoints: {
  150.             if (SR_PointPipe(
  151.                     srPrivate, 
  152.                     (TQ3Point3D *)lineData->vertices, 
  153.                     numVertices, 
  154.                     sizeof(TQ3Vertex3D),
  155.                     &color,
  156.                     NULL,
  157.                     DO_POLYLINE) == kQ3Failure) {
  158.                 return (kQ3Failure);
  159.             }
  160.             break;
  161.         }
  162.         default: {
  163.             return (kQ3Failure);
  164.             break;
  165.         }
  166.     }
  167.  
  168.     return (kQ3Success);
  169. }
  170.